package org.lma;

import java.util.ArrayList;
import java.util.List;

public class LemmaPath {

	private Lemma[] lemmas = null;
	
	public LemmaPath(List<Lemma> list) {
		lemmas = list.toArray(new Lemma[]{});
	}
	
	public double caculate() {
		double result = 10;
		if(lemmas != null && lemmas.length > 0) {
			int length = lemmas.length;
			int[] lens = new int[lemmas.length];
			
			for(int i = 0; i < length; i ++) {
				Lemma lemma = lemmas[i];
				lens[i] = lemma.getLength();
				
				if(lemma.getLength() == 1) {
					result -= 1;
				}
			}
			
			result += length;
			
			result -= LemmaUtil.variance(lens);
		}
		return result;
	}
	
	public List<String> getText(String text) {
		List<String> rs = new ArrayList<String>(lemmas.length);
		for(Lemma l : lemmas) {
			rs.add(text.substring(l.getBegin(), l.getBegin() + l.getLength()));
		}
		return rs;
	}
}
